import json
import os

def read_template(file_path):
    with open(file_path, 'r', encoding='utf-8') as f:
        return f.read()

def read_translations(file_path):
    with open(file_path, 'r', encoding='utf-8') as f:
        return json.load(f)

def generate_html(header_template, footer_template, translations, lang_code):
    # Get language specific translations
    lang_data = translations[lang_code]
    
    # Replace placeholders in header
    content = header_template
    for key, value in lang_data.items():
        content = content.replace('{{' + key + '}}', value)
    
    # Add language specific content (to be implemented)
    content += '<body>\n    <div class="scrollblock block-title">\n'
    
    # Add footer
    footer_content = footer_template
    for key, value in lang_data.items():
        footer_content = footer_content.replace('{{' + key + '}}', value)
    content += footer_content
    
    return content

def main():
    # Read templates and translations
    header_template = read_template('templates/header.html')
    footer_template = read_template('templates/footer.html')
    translations = read_translations('templates/translations.json')
    
    # Generate HTML for each language
    for lang_code in translations.keys():
        output_file = f'index.{lang_code}.html' if lang_code != 'zh-CN' else 'index.html'
        html_content = generate_html(header_template, footer_template, translations, lang_code)
        
        with open(output_file, 'w', encoding='utf-8') as f:
            f.write(html_content)
        print(f'Generated {output_file}')

if __name__ == '__main__':
    main()